package taller2.controller.listeners;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import taller2.controller.modes.Mode;
import taller2.view.draws.DrawingArea;

public class MouseHandler implements MouseListener,MouseMotionListener{
	private DrawingArea area;
	private Mode mode;
	
	// constructor
	public MouseHandler(DrawingArea area, Mode mode){
		this.mode = mode;
		this.area = area;
	}
	
	// changes the mode
	public void ChangeMode(Mode mode){
		this.mode = mode;
	}
	
	// when the mouse is dragged
	public void mouseDragged(MouseEvent arg0) {	
		if(mode != null)
			mode.whenDragged(arg0,area);	
	}

	public void mouseMoved(MouseEvent arg0) {}

	public void mouseClicked(MouseEvent arg0) {}

	public void mouseEntered(MouseEvent arg0) {}

	public void mouseExited(MouseEvent arg0) {}

	// when the mouse is pressed
	public void mousePressed(MouseEvent arg0) {	
		if(mode != null)
			mode.whenPressed(arg0,area);
	}

	// when the mouse is released
	public void mouseReleased(MouseEvent arg0) {
		if(mode != null)
		mode.whenReleased(arg0,area);
	}
}